<?php
/**
 * Created by PhpStorm.
 * User: alice
 * Date: 2015/12/29
 * Time: 9:18
 */

class Involved_ProductCateModel extends BaseModel
{
    protected $table = 'product_cate';

    /**
     * 获取产品分类信息
     * return ProductCate
     */
    public function GetGoodsCateList()
    {
        return DB::table($this->table)->paginate(8);
    }

    /**
     * 获取添加产品分类列表
     * @return mixed
     */
    public function GetProductCateList()
    {
        return DB::table($this->table)->get();
    }

    public function GetGoodsCateInfo($id)
    {
        return DB::table($this->table)->where('cate_id',$id)->first();
    }

    public function GetListByParentId($id, $filed = array())
    {
        $db = DB::table($this->table);
        if (!empty($filed)) {
            $db->select($filed);
        }
        return $db->where('parent_id',$id)->get();
    }


    public function GetProductCateDetail($classes)
    {
        return DB::table($this->table)
                ->select('cate_name','introduce')
                ->where('cate_id',$classes)
                ->first();
    }

    /**
     * 获取产品材质
     * @return mixed
     * @author alice
     * @date 2016-1-26
     */
    public function GetQualityList()
    {
        return DB::table($this->table)
            ->select('cate_id','cate_name')
            ->where('length',ProductEnum::PRODUCT_LEVEL_THREE)
            ->get();
    }

    /**
     * 获取产品分类
     * @param $quality
     * @return mixed
     * @author alice
     * @date 2016-2-21
     */
    public function GetCategoryById($quality)
    {
        return DB::table($this->table)
            ->select('cate_id','cate_name','length')
            ->where('parent_id',$quality)
            ->first();
    }

    /**
     * 获取产品品类
     * @param $category
     * @return mixed
     * @author alice
     * @date 2016-2-21
     */
    public function GetClassesById($category)
    {
        return DB::table($this->table)
            ->select('cate_id','cate_name','length')
            ->where('parent_id',$category)
            ->first();
    }

    /**
     * 获取产品分类
     * @return mixed
     * @author alice
     * @date 2016-2-24
     */
    public function GetProductCategory()
    {
        return DB::table($this->table)
            ->select('cate_id','cate_name')
            ->where(['parent_id' => 0, 'length' => 1])
            ->get();
    }

    #获取品类
    public function GetProductClasses($cate_id)
    {
        return DB::table($this->table)
            ->select('cate_id','cate_name')
            ->where(['parent_id' => $cate_id, 'length' => 2])
            ->get();
    }

    /**
     * 获取上级分类ID
     * @param $cate_id
     * @return mixed
     * @author buluota
     * @date 2016-03-08
     */
    public function GetParentCate($cate_id)
    {
        $cate = DB::table($this->table)
            ->select('cate_id','cate_name','parent_id')
            ->where('cate_id',$cate_id)
            ->first();
        return empty($cate) ? NULL : $cate->parent_id;
    }


    /**
     * 获取材质信息
     * @param $cate_id
     * @return mixed
     * @author buluota
     * @date 2016-03-08
     */
    public function GetProductQuality($cate_id)
    {
        return DB::table($this->table)
            ->select('cate_id','cate_name','parent_id')
            ->where(['parent_id' => $cate_id, 'length' => 3])
            ->get();
    }


}